﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.FireProjects.BLL;
using Yipusoft.FireProjects.Model;
using Yipusoft.Common.Model;
using Yipusoft.Common.BLL;

public partial class BasicBase_Drilling_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            init();
        }

    }

    void init()
    {
        string NoteID = Request.QueryString["id"];
        string where = " NoteId='" + NoteID + "'";
        UserGrid.DataSource = DrillingDepartment.GetList(where + "  and IsActive=1 ");
        UserGrid.DataBind();
        GridView1.DataSource = DrillingDepartment.GetList(where + "  and IsActive=0 ");
        GridView1.DataBind();
    }

    protected void UserGrid_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lblID = e.Row.FindControl("lblID") as Label;
            lblID.Text = Convert.ToString(e.Row.RowIndex + 1);
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
        }
    }
    //添加
    protected void Button1_Click(object sender, EventArgs e)
    {
        DrillingDepartmentInfo info = new DrillingDepartmentInfo();
        info.IsActive = Convert.ToInt32(IsActive.Checked);
        info.NoteId = new Guid(Request.QueryString["id"]);
        info.PeopleCount = Convert.ToInt32(PeopleCount.Text);
        info.VehicleCount = Convert.ToInt32(VehicleCount.Text);
        info.Department = Department.Text;
        Guid id = DrillingDepartment.Insert(info);
        if (id != Guid.Empty)
        {
            EventLogInfo log = new EventLogInfo();
            log.EventTime = DateTime.Now;
            log.EventType = 1;
            log.EventData = "添加新记录";
            log.ItemID = id.ToString();
            log.ItemName = "DrillingDepartment";
            log.ItemFullUrl = "Drilling/DrillingDepartment.aspx";
            log.CreatedBy = Context.User.Identity.Name;
            log.CreatedTime = DateTime.Now;
            log.UserIP = Request.UserHostAddress;
            EventLog.Insert(log);
            init();
            Prompt.Text = "提示：添加成功！";
        }
        else
        {
            Prompt.Text = "提示：添加失败！";
        }

    }
    protected void UserGrid_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Del")
        {
            if (DrillingDepartment.Delete(new Guid(e.CommandArgument.ToString())))
            {
                EventLogInfo log = new EventLogInfo();
                log.EventTime = DateTime.Now;
                log.EventType = 1;
                log.EventData = "删除一条参加单位";
                log.ItemID = e.CommandArgument.ToString();
                log.ItemName = "DrillingDepartment";
                log.ItemFullUrl = "Drilling/DrillingDepartment.aspx";
                log.CreatedBy = Context.User.Identity.Name;
                log.CreatedTime = DateTime.Now;
                log.UserIP = Request.UserHostAddress;
                EventLog.Insert(log);
                init();
                Prompt.Text = "提示：删除成功！";
            }
            else
            {
                Prompt.Text = "提示：删除失败！";
            }
        }
    }
}
